﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>Value is Type - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="Within an expression, the &quot;Value is Type&quot; statement checks whether a value is of a given type or is numeric, uppercase, etc." />
<meta name="ahk:equiv-v1" content="commands/IfIs.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1><em>Value</em> is <em>Type</em></h1>

<p>Within an expression, checks whether a value is of a given type or is numeric, uppercase, etc. </p>

<pre class="Syntax"><span class="func">if</span> <i>Value</i> is <i>Type</i>
<span class="func">if</span> !(<i>Value</i> is <i>Type</i>) </pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Value</dt>
  <dd><p>An <a href="../Variables.htm#Expressions">expression</a> which produces the value to check.</p></dd>

  <dt>Type</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a> or <a href="../Concepts.htm#objects">Object</a></p>
    <p>An <a href="../Variables.htm#Expressions">expression</a> which produces a type string or object, as described below.</p>
  </dd>

</dl>

<h2 id="Types">Type Strings</h2>
<p>Type strings are case-insensitive.</p>
<table class="info">
  <tr>
    <th>&nbsp;</th><th></th>
  </tr>
  <tr id="integer">
    <td style="width:15%">integer</td>
    <td>True if <em>Value</em> is an integer or a purely numeric string (decimal or hexadecimal) without a decimal point. Leading and trailing spaces and tabs are allowed. The string may start with a plus or minus sign and must not be empty.</td>
  </tr>
  <tr id="float">
    <td>float</td>
    <td>True if <em>Value</em> is a floating point number or a purely numeric string containing a decimal point. Leading and trailing spaces and tabs are allowed.  The string may start with a plus sign, minus sign, or decimal point and must not be empty.</td>
  </tr>
  <tr id="number">
    <td>number</td>
    <td>True if <code><i>Value</i> is "integer" or <i>Value</i> is "float"</code> is true.</td>
  </tr>
  <tr id="object">
    <td>object</td>
    <td>True if <em>Value</em> is an <a href="../Objects.htm">object</a>.</td>
  </tr>
  <tr id="byref">
    <td>byref</td>
    <td>True if <em>Value</em> is a reference to a <a href="../Functions.htm#ByRef">ByRef parameter</a> and the function's caller passed a variable reference.</td>
  </tr>
  <tr>
    <th>Strings</th><th></th>
  </tr>
  <tr>
    <td>digit</td>
    <td>True if <em>Value</em> is a positive integer, an empty string, or a string which contains only the characters 0 through 9. Other characters such as the following are not allowed: spaces, tabs, plus signs, minus signs, decimal points, hexadecimal digits, and the 0x prefix.</td>
  </tr>
  <tr>
    <td>xdigit</td>
    <td>Hexadecimal digit: Same as <em>digit</em> except the characters A through F (uppercase or lowercase) are also allowed. A prefix of 0x is tolerated if present.</td>
  </tr>
  <tr>
    <td>alpha</td>
    <td>True if <em>Value</em> is a string and is empty or contains only alphabetic characters. False if there are any digits, spaces, tabs, punctuation, or other non-alphabetic characters anywhere in the string. 例如, if <em>Value</em> contains a space followed by a letter, it is <em>not</em> considered to be <em>alpha</em>. </td>
  </tr>
  <tr>
    <td>upper</td>
    <td>True if <em>Value</em> is a string and is empty or contains only uppercase characters. False if there are any digits, spaces, tabs, punctuation, or other non-uppercase characters anywhere in the string.</td>
  </tr>
  <tr>
    <td>lower</td>
    <td>True if <em>Value</em> is a string and is empty or contains only lowercase characters. False if there are any digits, spaces, tabs, punctuation, or other non-lowercase characters anywhere in the string.</td>
  </tr>
  <tr>
    <td>alnum</td>
    <td>Same as <em>alpha</em> except that integers and characters 0 through 9 are also allowed.</td>
  </tr>
  <tr>
    <td>space</td>
    <td>True if <em>Value</em> is a string and is empty or contains only whitespace consisting of the following characters: space (<a href="../Variables.htm">A_Space</a> or `s), tab (<a href="../Variables.htm">A_Tab</a> or `t), linefeed (`n), return (`r), vertical tab (`v), and formfeed (`f).</td>
  </tr>
  <tr id="time">
    <td>time</td>
    <td><p>True if <em>Value</em> is a valid date-time stamp, which can be all or just the leading part of the <a href="FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format. 例如, a 4-digit string such as 2004 is considered valid. Use <a href="StrLen.htm">StrLen</a> to determine whether additional time components are present.</p>
      <p>Years less than 1601 are not considered valid because the operating system generally does not support them. The maximum year considered valid is 9999. </p>
      <p>The word DATE may be used as a substitute for the word TIME, with the same result.</p>
    </td>
  </tr>
</table>

<h2 id="Objects">Objects</h2>
<p>If <em>Type</em> is an <a href="../Objects.htm">object</a>, the result is true if <em>Value</em> is an object derived from <em>Type</em>, directly or indirectly. 例如:</p>
<pre>x := {}
y := new x  <em>; Equivalent to y := {base: x}</em>
z := new y
MsgBox(x is x)  <em>; False</em>
MsgBox(y is x)  <em>; True</em>
MsgBox(z is x)  <em>; True</em>
</pre>

<h2 id="Remarks">备注</h2>
<p><code>is</code> can be used anywhere an expression is expected. <a href="../Variables.htm#Operators">Precedence rules</a> apply, so for instance, <code>x or y is z</code> is the same as <code>x or (y is z)</code>.</p>
<p>To check for multiple types, use <code>is</code> multiple times. 例如, <code>x is "integer" or x is "space"</code>.</p>
<p>Since literal numbers such as <code>128</code>, <code>0x7F</code> and <code>1.0</code> are converted to pure numbers before the script begins executing, the format of the literal number is lost. Consequently, type checks act on the decimal form of the number. 例如, <code>0x7F is "digit"</code> is equivalent to <code>"128" is "digit"</code>.</p>
<p>The system locale is ignored unless <a href="StringCaseSense.htm">StringCaseSense Locale</a> has been used.</p>

<h2 id="Related">相关</h2>
<p><a href="../Variables.htm#YYYY">A_YYYY</a>, <a href="FileGetTime.htm">FileGetTime</a>, <a href="If.htm">If</a>, <a href="StrLen.htm">StrLen</a>, <a href="InStr.htm">InStr</a>, <a href="StrLower.htm">StrUpper</a>, <a href="DateAdd.htm">DateAdd</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>if var is "float"
    MsgBox var " is a floating point number."
else if var is 'integer'
    MsgBox var " is an integer."
if var is "time"
    MsgBox var " is also a valid date-time."</pre>
</div>

</body>
</html>